<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-page-header style="background-color: #0096dc;color: white;line-height: 60px"
                    @back="goBack" content="修改轮播图页面">
    </el-page-header>
    <el-card style="width: 600px;height: 800px;margin: 0 auto">
        <el-form label-width="80px">
            <el-form-item label="轮播图标题"><el-input type="text" v-model="b.title"></el-input></el-form-item>
            <el-form-item label="排序"><el-input type="text" v-model="b.sort"></el-input></el-form-item>
            <el-form-item label="广告位置"><el-input type="text" v-model="b.location"></el-input></el-form-item>
            <el-form-item label="状态"><el-input type="text" v-model="b.status"></el-input></el-form-item>
            <el-form-item label="轮播图图片">
    <img :src="oldUrl" width="200" alt="">
    <el-upload
            action="/upload"
            name="picFile"
            limit="1"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-success="handleSuccess"
            :on-remove="handleRemove">
        <i class="el-icon-plus"></i>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="update()">修改轮播图</el-button>
            </el-form-item>
        </el-form>
    </el-card >

</div>
</body>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                b:{title:"",sort:"",
                    location:"",status:""},
                oldUrl:""
            }
        },
        methods:{
            update() {
                //发请求
                axios.post("/banner/update",v.b).then(function (response) {
                    location.href="/admin.html";//回到后台管理页面
                })
            },
            goBack(){
                //返回上一页面
                history.back();
            },
            handleSuccess(response,file,fileList){
                v.b.url=response;
            },
            handleRemove(file, fileList) {
                v.b.url=v.oldUrl;
                axios.get("/remove?url="+file.response).then(function () {
                    console.log("删除文件完成!")
                })
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }
        },
        created:function (){
            //发出请求获取轮播图详情信息
            axios.get("/banner/selectUpdateById"+location.search).then(function (response) {
                v.b=response.data;
                //把原来图片的路径用单独的一个变量记录，避免联动
                v.oldUrl=v.b.url;
            })
        }
    })
</script>
</html>